package cn.com.web.Servlet;

import cn.com.domain.Customer;
import cn.com.domain.Room;
import cn.com.service.CustomerService;
import cn.com.service.RoomService;
import cn.com.service.impl.CustomerServiceImpl;
import cn.com.service.impl.RoomServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/AddRoomServlet")
public class AddRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String room_name = request.getParameter("room_name");
        double room_price = Double.valueOf(request.getParameter("room_price"));
        double room_area = Double.valueOf(request.getParameter("room_area"));
        int room_remains = Integer.parseInt(request.getParameter("room_remains"));
        Room room=new Room(null,room_name,room_price,room_area,room_remains);
        RoomService service=new RoomServiceImpl();
        service.addRoom(room);
        //返回到查询页面
        request.getRequestDispatcher("FindRoomByPageServlet?currentPage=1&rows=5")
                .forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
